import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import '../../provide/cart_page_provide.dart';

class CartCount extends StatelessWidget {
  var item;
  CartCount(this.item);
  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenUtil().setWidth(165),
      margin: EdgeInsets.only(top:5.0),
      decoration: BoxDecoration(
        border: Border.all(width: 1.0,color: Colors.black12)
      ),
      child: Provide<CartPageProvide>(builder: (context,child,val){
        return  Row(
        children: <Widget>[
          _reduceBtn(context), _countArea(),_addBtn(context)
        ],
      );
      },)
    );
  }

  Widget _reduceBtn(context){
    return InkWell(
      onTap: (){
        Provide.value<CartPageProvide>(context).addOrReduceAction(item, 'reduce');
      },
      child: Container(
        width: ScreenUtil().setWidth(45),
        height: ScreenUtil().setWidth(45),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            right: BorderSide(width: 1,color: Colors.black12)
          )
        ),
        child: Text('-'),
      ),
    );
  }

    Widget _addBtn(context){
    return InkWell(
      onTap: (){
                Provide.value<CartPageProvide>(context).addOrReduceAction(item, 'add');

      },
      child: Container(
        width: ScreenUtil().setWidth(45),
        height: ScreenUtil().setWidth(45),
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            left: BorderSide(width: 1,color: Colors.black12)
          )
        ),
        child: Text('+'),
      ),
    );
  }

  Widget _countArea(){
    return Container(
              width: ScreenUtil().setWidth(45),
        height: ScreenUtil().setWidth(45),
        alignment: Alignment.center,
        color: Colors.white,
        child: Text('${item.count}'),
    );
  }
}